<?php
namespace App\Services;

use App\Models\WxError;
/**
 * 微信错误服务类,解决微信接口返回错误信息难识别的问题
 * @package App\Services
 */
class WxErrorService
{
    /**
     * 检查微信接口请求，返回中文提示
     * @param $apiRs
     * @return bool
     * @throws \Exception
     */
    public static function checkApiResponse($apiRs)
    {
        if (isset($apiRs['errcode']) && $apiRs['errcode'] != 0) {
            $find = WxError::where('errcode', $apiRs['errcode'])->first();
            if (!empty($find)){
                throw new \Exception($apiRs['errcode'].':'.$find->errmsg);
            }else{
                throw new \Exception('接口错误：'. $apiRs['errcode'] .':' . $apiRs['errmsg']);
            }
        }
        return true;
    }
}